package com.example.materials_management.repository;

import com.example.materials_management.entity.ImportInfoEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface ImportInfoRepository extends JpaRepository<ImportInfoEntity, Integer> {
    @Query(value = "SELECT * FROM import_info" +
            " WHERE (:materialId is null or material_id = :materialId)" +
            " AND (:operateLocation is null or operate_location LIKE %:operateLocation%)" +
            " AND (:applicants is null or applicants LIKE %:applicants%)" +
            " AND (:operator is null or operator LIKE %:operator%)" +
            " AND (:amountMin is null or amount >= :amountMin)" +
            " AND (:amountMax is null or amount <= :amountMax)", nativeQuery = true)
    List<Map<String, Object>> findItems(
            @Param("materialId") Integer materialId,
            @Param("operateLocation") String operateLocation,
            @Param("applicants") String applicants,
            @Param("operator") String operator,
            @Param("amountMin") Integer amountMin,
            @Param("amountMax") Integer amountMax
    );

    @Query(value = "SELECT id FROM export_info", nativeQuery = true)
    List<Integer> getIds();

}
